package com.hxx.widget

import com.hxx.widget.richtext.editor.BaseEditorSaveStater
import com.hxx.widget.richtext.editor.EditorHistory
import com.hxx.widget.richtext.editor.EditorSaveStater
import org.junit.Test

class EditorSaveStaterUnitTest {
    @Test
    fun test() {
        val saver = BaseEditorSaveStater.instance()
        assert(!saver.canRedo())
        assert(!saver.canUndo())
        val node0 = EditorHistory("", "1", 0)
        val node1 = EditorHistory("", "2", 1)
        val node2 = EditorHistory("", "3", 2)
        val node3 = EditorHistory("", "4", 3)
        val node4 = EditorHistory("", "5", 4)
        saver.setStateChangedListener(object : EditorSaveStater.OnStateChangedListener {
            override fun onChanged() {
                System.out.println("变化:${saver.canRedo()},${saver.canUndo()}")
            }
        })
        saver.saveNode(node0)
        saver.saveNode(node1)
        saver.saveNode(node2)
        saver.saveNode(node3)
        saver.saveNode(node4)

        assert(saver.canUndo())
        saver.undoNode()
        saver.undoNode()
        saver.undoNode()
        saver.undoNode()
        assert(saver.canUndo())
        saver.undoNode()
        assert(!saver.canUndo())
        assert(saver.canRedo())

    }
}